import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../pages/Login.vue'
import shopHome from '../pages/shop/Home.vue'
import AddRentGoods from '../pages/shop/goods/Add-Rent.vue' 
import AddShareGoods from '../pages/shop/goods/Add-Share.vue' 
import ListRentGoods from '../pages/shop/goods/List-Rent.vue' 
import ListShareGoods from '../pages/shop/goods/List-Share.vue' 
import ShopAccount from '../pages/shop/account/Account.vue'
import ShopOrder from '../pages/shop/order/Order.vue'
import ShopWelcome from '../pages/shop/Welcome.vue'
import ShopReport from '../pages/shop/report/Report.vue'
import UserWelcome from '../pages/user/Welcome.vue'
import UserHome from '../pages/user/Home.vue'
import UserRentalGoods from '../pages/user/goods/RentalGood.vue'
import UserRentalGoodsDetail from '../pages/user/goods/RentalGoodDetail.vue'
import UserRentalOrder from '../pages/user/order/RentalOrder.vue'
import UserCart from '../pages/user/cart/Cart.vue'
import UserCollect from '../pages/user/collect/Collect.vue'
import UserShareGoods from '../pages/user/goods/ShareGood.vue'
import UserShareGoodsDetail from '../pages/user/goods/ShareGoodDetail.vue'
import UserShareOrder from '../pages/user/order/ShareOrder.vue'
import UserPersonalOrder from '../pages/user/order/MyOrder.vue'
import UserAccount from '../pages/user/account/Account.vue'
import AdminHome from '../pages/administer/Home.vue'
import AdminUser from '../pages/administer/User.vue'
import AdminMerchant from '../pages/administer/Merchant.vue'
import AdminCate from '../pages/administer/Cate.vue'
import AdminWelcome from '../pages/administer/Welcome.vue'
Vue.use(VueRouter)



const router = new VueRouter({
  mode:'hash',
  
  routes:[
    {path:'/',redirect:'/user'},
    {path:'/login',component:Login},
    {path:'/shop',component:shopHome,redirect:'/welcome',children:[
      {path:'/welcome',component:ShopWelcome},
      {path:'/order',component:ShopOrder},
      {path:'/shopAccount',component:ShopAccount},
      {path:'/report',component:ShopReport},
      {path:'/addRent',component:AddRentGoods},
      {path:'/addShare',component:AddShareGoods},
      {path:'/listRent',component:ListRentGoods},
      {path:'/listShare',component:ListShareGoods},
    ]},
    {path:'/user',component:UserHome,redirect:'/userwelcome',children:[
      {path:'/userwelcome',component:UserWelcome},
      {path:'/goodlist',component:UserRentalGoods},
      {path:'/rentalDetail',component:UserRentalGoodsDetail},
      {path:'/rentalOrder',component:UserRentalOrder},
      {path:'/shareOrder',component:UserShareOrder},
      {path:'/sharegoodlist',component:UserShareGoods},
      {path:'/shareDetail',component:UserShareGoodsDetail},
      {path:'/userCart',component:UserCart},
      {path:'/userCollect',component:UserCollect},
      {path:'/myOrder',component:UserPersonalOrder},
      {path:'/userAccount',component:UserAccount}
    ]},
    {path:'/admin',component:AdminHome,redirect:'/adminwelcome',children:[
      {path:'/adminwelcome',component:AdminWelcome},
      {path:'/adminUser',component:AdminUser},
      {path:'/adminMerchant',component:AdminMerchant},
      {path:'/adminCate',component:AdminCate}
    ]}
    
  ]
})

router.beforeEach((to,from,next)=>
{
  if(to.path=="/login"||to.path=="/userwelcome"||to.path=="/goodlist"||to.path=="/sharegoodlist")
    return next();
  const tokenStr1=window.sessionStorage.getItem("user");
  const tokenStr2=window.sessionStorage.getItem("merchant");
  const tokenStr3=window.sessionStorage.getItem("admin");
  
  if(!tokenStr1&&!tokenStr2&&!tokenStr3)
    return next("/login");
    next();
})

export default router
